#include "Observer.h"
using namespace std;
using namespace adevs;

// Assign a locally unique number to the input port
const int Observer::in_departed = 0;

Observer::Observer():
Atomic<IO_Type>(),
	total_waiting_time(0.0),
	max_waiting_time(0.0),
	car_count(0)
{
}

double Observer::ta()
{
	// The Observer has no autonomous behavior, so its next event
	// time is always infinity.
	return DBL_MAX;
}

void Observer::delta_int()
{
	// The Observer has no autonomous behavior, so do nothing
}

void Observer::delta_ext(double e, const Bag<IO_Type>& xb)
{
	Bag<IO_Type>::const_iterator i;
	for (i = xb.begin(); i != xb.end(); i++)
	{
		const Vehicle* c = (Vehicle*)(*i).value;

		// Compute the time spent waiting in line 
		double waiting_time = (c->t_end-c->t_start);

		total_waiting_time += waiting_time;
		if (waiting_time > max_waiting_time)
			max_waiting_time = waiting_time;
		car_count++;
	}
}

void Observer::delta_conf(const Bag<IO_Type>& xb)
{
	// The Observer has no autonomous behavior, so do nothing
}

void Observer::output_func(Bag<IO_Type>& yb)
{
	// The Observer produces no output, so do nothing
}

void Observer::gc_output(Bag<IO_Type>& g)
{
	// The Observer produces no output, so do nothing
}

Observer::~Observer()
{
}
